﻿
using Admin.NET.Core.Btms;

namespace Admin.NET.Application.Service;

/// <summary>
/// 血型申请复核表
/// </summary>
public class TraFuHeService : BaseServiceString<TraFuHe>
{
    private readonly BillNoManager _billNoManager;
    public TraFuHeService(SqlSugarRepository<TraFuHe> rep, BillNoManager billNoManager) : base(rep)
    {
        _billNoManager = billNoManager;
    }

    /// <summary>
    /// 获取列表
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task<SqlSugarPagedList<TraFuHeOutput>> Page(BaseKeywordPageInput input)
    {
        var traShenQingFuHeList = await Queryable.FuzzyQuery(input.Keyword, new List<string> { "id" })
           .Select<TraFuHeOutput>()
           .OrderByDescending(it => it.Id)
           .ToPagedListAsync(input.Page, input.PageSize);

        return traShenQingFuHeList;
    }

    /// <summary>
    /// 通过Id获取
    /// </summary>
    public async Task<TraFuHeOutput> Get(string id)
    {
        var entity = await Queryable.Where(x => x.Id == id).ToListAsync();
        if (entity.Count > 0)
        {
            return GetById<TraFuHeOutput>(id);  
        }
        else
        {
            return new TraFuHeOutput();
        }
    }

    /// <summary>
    /// 新增成功后返回主键
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public TraFuHe Add(TraFuHeInput input)
    {
        input.danJuZhuangTai = DanJuZhuangTai.已生效;
        return AddWithInput(input);
    }

    /// <summary>
    /// 更新成功后返回true
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    public bool Update(TraFuHeInput input)
    {
        return UpdateWithInput(input);
    }
}
